<template>
  <div style="position: relative">
    <div style="position: absolute;top:200px;left:300px">
      <el-cascader
          :options="ziyuan"
          :props="props"
          @change="resource"
          placeholder="请选择资源信息"
          clearable
      ></el-cascader>
    </div>
    <div style="position: absolute;top:200px;left: 900px">
      <el-select v-model="value" placeholder="请选择用户" @click="add_u">
        <el-option
            v-for="item in user"
            :key="item.value"
            :label="item.label"
            :value="item.value"
        >
        </el-option>
      </el-select>
    </div>
    <div style="position: absolute;top: 100px;right: 200px">
      <button @click="post_resource"
              style="color: white;background-color: #2f54eb;width: 100px;height: 35px;border: none;">确定
      </button>
    </div>
  </div>

</template>

<script>
import maxios from "@/http/axios";

export default {
  name: "add_jszy",
  data() {
    return {
      props: {multiple: true},
      ziyuan: [],
      list: [],
      user: [],
      value: '',
      user_id: ''
    }
  },
  methods: {
    get_resource() {
      maxios('/users/resource', 'get').then(res => {
        if (res.code == 200) {
          this.ziyuan = res.ziyuan
          this.user = res.users
        }
      })
    },
    resource(val) {
      this.list.push(val)
      console.log(this.list)
    },
    add_u(value) {
      this.user_id = value
      console.log(this.user_id)

    },

    post_resource() {
      maxios('/users/resource', 'post', {'user_id': this.user_id, 'res_id': this.list}).then(res => {
        if (res.code == 200) {
          this.$toast.success('添加成功')
        }
      })
    },
  },
  mounted() {
    this.get_resource()
  }

}

</script>

<style scoped>

</style>